﻿Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.Windows.Forms.VisualStyles
Imports System.ComponentModel

<ToolboxBitmap(GetType(TabControl))> _
Public Class StylishTabControl : Inherits TabControl

#Region "    Declarations"
    Private Const WM_SETFONT As Integer = &H30
    Private Const WM_FONTCHANGE As Integer = &H1D

    Private _DisplayManager As TabControlDisplayManager = TabControlDisplayManager.Framework

    Private iBackColor As Color = SystemColors.ControlLightLight
    Private iBackColorGradient1 As Color = SystemColors.ControlLightLight
    Private iBackColorGradient2 As Color = SystemColors.ControlLight
    Private iBorderColor As Color = ThemedColors.ToolBorder
    Private iTabHeightIncrementor As Integer = 20
    Private iTabActiveBackColorGradient1 As Color = SystemColors.ControlLightLight
    Private iTabActiveBackColorGradient2 As Color = SystemColors.ControlLightLight
    Private iTabBackColorGradient1 As Color = SystemColors.Control
    Private iTabBackColorGradient2 As Color = SystemColors.ControlDark
    Private iTabBorderColor As Color = SystemColors.ControlDark
    Private iTabActiveBorderColor As Color = ThemedColors.ToolBorder
    Private iTabDisabledForeColor As Color = SystemColors.ControlDark
    Private iTabEnabledForeColor As Color = SystemColors.ControlText
    Private iMouseOverTabIndex As Integer = -1
#End Region

#Region "    Properties "
    <System.ComponentModel.DefaultValue(GetType(TabControlDisplayManager), "Framework"), System.ComponentModel.Category("Appearance")> _
    Public Property DisplayManager() As TabControlDisplayManager
        Get
            Return _DisplayManager
        End Get
        Set(ByVal value As TabControlDisplayManager)
            _DisplayManager = value
            If Me._DisplayManager.Equals(TabControlDisplayManager.Framework) Then
                Me.SetStyle(ControlStyles.UserPaint, True)
                Me.ItemSize = New Size(0, 15)
                Me.Padding = New Point(9, 0)
            Else
                Me.ItemSize = New Size(0, 0)
                Me.Padding = New Point(6, 3)
                Me.SetStyle(ControlStyles.UserPaint, False)
            End If
        End Set
    End Property
    Public Overrides Property BackColor As Color
        Get
            Return Me.iBackColor
        End Get
        Set(value As Color)
            Me.iBackColor = value
            Me.Invalidate()
        End Set
    End Property
    Public Property BackColorGradient1 As Color
        Get
            Return Me.iBackColorGradient1
        End Get
        Set(value As Color)
            Me.iBackColorGradient1 = value
            Me.Invalidate()
        End Set
    End Property
    Public Property BackColorGradient2 As Color
        Get
            Return Me.iBackColorGradient2
        End Get
        Set(value As Color)
            Me.iBackColorGradient2 = value
            Me.Invalidate()
        End Set
    End Property
    Public Property BorderColor As Color
        Get
            Return Me.iBorderColor
        End Get
        Set(value As Color)
            Me.iBorderColor = value
            Me.Invalidate()
        End Set
    End Property
    Public Property TabHeightIncrementor As Integer
        Get
            Return Me.iTabHeightIncrementor
        End Get
        Set(value As Integer)
            Me.iTabHeightIncrementor = value
            Me.OnFontChanged(New EventArgs())
        End Set
    End Property
    Public Property TabActiveBackColorGradient1 As Color
        Get
            Return Me.iTabActiveBackColorGradient1
        End Get
        Set(value As Color)
            Me.iTabActiveBackColorGradient1 = value
            Me.Invalidate()
        End Set
    End Property
    Public Property TabActiveBackColorGradient2 As Color
        Get
            Return Me.iTabActiveBackColorGradient2
        End Get
        Set(value As Color)
            Me.iTabActiveBackColorGradient2 = value
            Me.Invalidate()
        End Set
    End Property
    Public Property TabBackColorGradient1 As Color
        Get
            Return Me.iTabBackColorGradient1
        End Get
        Set(value As Color)
            Me.iTabBackColorGradient1 = value
            Me.Invalidate()
        End Set
    End Property
    Public Property TabBackColorGradient2 As Color
        Get
            Return Me.iTabBackColorGradient2
        End Get
        Set(value As Color)
            Me.iTabBackColorGradient2 = value
            Me.Invalidate()
        End Set
    End Property
    Public Property TabBorderColor As Color
        Get
            Return Me.iTabBorderColor
        End Get
        Set(value As Color)
            Me.iTabBorderColor = value
            Me.Invalidate()
        End Set
    End Property
    Public Property TabActiveBorderColor As Color
        Get
            Return Me.iTabActiveBorderColor
        End Get
        Set(value As Color)
            Me.iTabActiveBorderColor = value
            Me.Invalidate()
        End Set
    End Property
    Public Property TabDisabledForeColor As Color
        Get
            Return Me.iTabDisabledForeColor
        End Get
        Set(value As Color)
            Me.iTabDisabledForeColor = value
            Me.Invalidate()
        End Set
    End Property
    Public Property TabEnabledForeColor As Color
        Get
            Return Me.iTabEnabledForeColor
        End Get
        Set(value As Color)
            Me.iTabEnabledForeColor = value
            Me.Invalidate()
        End Set
    End Property
#End Region

#Region "    Constructor "
    Public Sub New()
        MyBase.New()
        If Me._DisplayManager.Equals(TabControlDisplayManager.Framework) Then
            Me.SetStyle(ControlStyles.UserPaint, True)
            Me.ItemSize = New Size(0, 15)
            Me.Padding = New Point(9, 0)
        End If
        Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
        Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
        Me.SetStyle(ControlStyles.ResizeRedraw, True)
        Me.ResizeRedraw = True
    End Sub
#End Region

#Region "    Private Methods "
    Private Function GetPath(ByVal index As Integer) As System.Drawing.Drawing2D.GraphicsPath
        Dim path As New System.Drawing.Drawing2D.GraphicsPath()
        path.Reset()

        Dim rect As Rectangle = Me.GetTabRect(index)

        If index = 0 Then
            path.AddLine(rect.Left + 1, rect.Bottom + 1, rect.Left + 1, rect.Bottom - rect.Height + 3) 'left side
            path.AddLine(rect.Left + 1, rect.Bottom - rect.Height + 3, rect.Left + 2, rect.Bottom - rect.Height + 3) 'right
            path.AddLine(rect.Left + 2, rect.Bottom - rect.Height + 3, rect.Left + 2, rect.Bottom - rect.Height + 2) 'up
            path.AddLine(rect.Left + 2, rect.Bottom - rect.Height + 2, rect.Left + 2, rect.Bottom - rect.Height + 2) 'right
            path.AddLine(rect.Left + 5, rect.Top, rect.Right - 5, rect.Top) 'top side
            path.AddLine(rect.Right - 4, rect.Top + 1, rect.Right - 3, rect.Top + 1) 'right
            path.AddLine(rect.Right - 3, rect.Top + 1, rect.Right - 2, rect.Top + 2) 'right-down
            path.AddLine(rect.Right - 2, rect.Top + 2, rect.Right - 2, rect.Top + 3) 'down
            path.AddLine(rect.Right - 2, rect.Top + 3, rect.Right - 1, rect.Top + 3) 'right
            path.AddLine(rect.Right - 1, rect.Top + 3, rect.Right - 1, rect.Top + rect.Height) 'down
        Else
            If index = Me.SelectedIndex Then
                path.AddLine(rect.Left, rect.Bottom + 1, rect.Left, rect.Top + 3) 'left side
                path.AddLine(rect.Left, rect.Top + 3, rect.Left + 1, rect.Top + 3) 'right
                path.AddLine(rect.Left + 1, rect.Top + 3, rect.Left + 1, rect.Top + 2) 'up
                path.AddLine(rect.Left + 1, rect.Top + 2, rect.Left + 2, rect.Top + 1) 'up-right
                path.AddLine(rect.Left + 2, rect.Top + 1, rect.Left + 3, rect.Top + 1) 'right
                path.AddLine(rect.Left + 3, rect.Top + 1, rect.Left + 4, rect.Top) 'up-right
                path.AddLine(rect.Left + 4, rect.Top, rect.Right - 4, rect.Top) 'top side
                path.AddLine(rect.Right - 3, rect.Top + 1, rect.Right - 2, rect.Top + 1) 'right
                path.AddLine(rect.Right - 2, rect.Top + 1, rect.Right - 1, rect.Top + 2) 'right-down
                path.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Top + 3) 'down
                path.AddLine(rect.Right - 1, rect.Top + 3, rect.Right, rect.Top + 3) 'right
                path.AddLine(rect.Right, rect.Top + 3, rect.Right, rect.Bottom + 1) 'down-side
            Else
                path.AddLine(rect.Left, rect.Bottom + 1, rect.Left, rect.Top + 3) 'left side
                path.AddLine(rect.Left, rect.Top + 3, rect.Left + 1, rect.Top + 3) 'right
                path.AddLine(rect.Left + 1, rect.Top + 3, rect.Left + 1, rect.Top + 2) 'up
                path.AddLine(rect.Left + 1, rect.Top + 2, rect.Left + 2, rect.Top + 1) 'up-right
                path.AddLine(rect.Left + 2, rect.Top + 1, rect.Left + 3, rect.Top + 1) 'right
                path.AddLine(rect.Left + 3, rect.Top + 1, rect.Left + 4, rect.Top) 'up-right
                path.AddLine(rect.Left + 4, rect.Top, rect.Right - 4, rect.Top) 'top side
                path.AddLine(rect.Right - 3, rect.Top + 1, rect.Right - 2, rect.Top + 1) 'right
                path.AddLine(rect.Right - 2, rect.Top + 1, rect.Right - 1, rect.Top + 2) 'right-down
                path.AddLine(rect.Right - 1, rect.Top + 2, rect.Right - 1, rect.Top + 3) 'down
                path.AddLine(rect.Right - 1, rect.Top + 3, rect.Right, rect.Top + 3) 'right
                path.AddLine(rect.Right, rect.Top + 3, rect.Right, rect.Bottom + 1) 'down-side
            End If
        End If

        Return path
    End Function
    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)

        '   Paint the Background
        Me.PaintTransparentBackground(e.Graphics, Me.ClientRectangle)

        'Measure and setup tab size
        'Me.SetupTabSize()

        '   Paint all the tabs
        If Me.TabCount > 0 Then
            For index As Integer = 0 To Me.TabCount - 1
                Me.PaintTab(e, index)
            Next
        End If

        '   paint a border round the pagebox
        '   We can't make the border disappear so have to do it like this.
        If Me.TabCount > 0 Then
            Dim borderRect As Rectangle = Me.TabPages(0).Bounds
            If Me.SelectedTab IsNot Nothing Then
                borderRect = Me.SelectedTab.Bounds
            End If
            borderRect.Inflate(1, 1)
            'ControlPaint.DrawBorder(e.Graphics, borderRect, ThemedColors.ToolBorder, ButtonBorderStyle.Solid)
            ControlPaint.DrawBorder(e.Graphics, borderRect, Me.iBorderColor, ButtonBorderStyle.Solid)
        End If

        'repaint the bit where the selected tab is
        Select Case Me.SelectedIndex
            Case -1
            Case 0
                Dim backPen As New Pen(Me.SelectedTab.BackColor)
                Dim selrect As Rectangle = Me.GetTabRect(Me.SelectedIndex)
                Dim selrectRight As Integer = selrect.Right
                e.Graphics.DrawLine(backPen, selrect.Left + 2, selrect.Bottom, selrectRight - 2, selrect.Bottom)
                e.Graphics.DrawLine(backPen, selrect.Left + 2, selrect.Bottom + 1, selrectRight - 2, selrect.Bottom + 1)
            Case Else
                Dim backPen As New Pen(Me.SelectedTab.BackColor)
                Dim selrect As Rectangle = Me.GetTabRect(Me.SelectedIndex)
                Dim selrectRight As Integer = selrect.Right
                e.Graphics.DrawLine(backPen, selrect.Left + 1, selrect.Bottom, selrect.Right - 1, selrect.Bottom)
                e.Graphics.DrawLine(backPen, selrect.Left + 1, selrect.Bottom + 1, selrect.Right - 1, selrect.Bottom + 1)
        End Select

    End Sub
    Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
        If Me.DesignMode Then
            Dim backBrush As New System.Drawing.Drawing2D.LinearGradientBrush(Me.Bounds, _
                                                                              Me.iBackColorGradient1, _
                                                                              Me.iBackColorGradient2, _
                                                                              Drawing2D.LinearGradientMode.Vertical)
            pevent.Graphics.FillRectangle(backBrush, Me.Bounds)
            backBrush.Dispose()
        Else
            Me.PaintTransparentBackground(pevent.Graphics, Me.ClientRectangle)
        End If
    End Sub
    Protected Sub PaintTransparentBackground(ByVal g As Graphics, ByVal clipRect As Rectangle)
        If (Me.Parent IsNot Nothing) Then
            clipRect.Offset(Me.Location)
            Dim e As PaintEventArgs = New PaintEventArgs(g, clipRect)
            Dim state As GraphicsState = g.Save
            g.SmoothingMode = SmoothingMode.HighSpeed
            Try
                g.TranslateTransform(CType(-Me.Location.X, Single), CType(-Me.Location.Y, Single))
                Me.InvokePaintBackground(Me.Parent, e)
                Me.InvokePaint(Me.Parent, e)

            Finally
                g.Restore(state)
                clipRect.Offset(-Me.Location.X, -Me.Location.Y)
            End Try
        Else
            Dim backBrush As New System.Drawing.Drawing2D.LinearGradientBrush(Me.Bounds, iBackColorGradient1, iBackColorGradient2, Drawing2D.LinearGradientMode.Vertical)
            g.FillRectangle(backBrush, Me.Bounds)
            backBrush.Dispose()
        End If
    End Sub
    Private Sub SetupTabSize()
        'measure tab text widths
        Dim tWidth As Integer = Me.ItemSize.Width
        Dim g As Graphics = Me.CreateGraphics
        For Each tb As TabPage In Me.TabPages
            Dim mSize As Size = g.MeasureString(tb.Text, Me.Font).ToSize
            If mSize.Width > tWidth Then tWidth = mSize.Width
        Next
        Me.ItemSize = New Size(tWidth + 25, Me.ItemSize.Height)
    End Sub
    Private Sub PaintTab(ByVal e As System.Windows.Forms.PaintEventArgs, ByVal index As Integer)

        Dim path As System.Drawing.Drawing2D.GraphicsPath = Me.GetPath(index)
        Me.PaintTabBackground(e.Graphics, index, path)
        Me.PaintTabBorder(e.Graphics, index, path)
        Me.PaintTabText(e.Graphics, index)
        Me.PaintTabImage(e.Graphics, index)

    End Sub
    Private Sub PaintTabBackground(ByVal graph As System.Drawing.Graphics, ByVal index As Integer, ByVal path As System.Drawing.Drawing2D.GraphicsPath)
        Dim rect As Rectangle = Me.GetTabRect(index)

        If rect.Height > 1 AndAlso rect.Width > 1 Then
            Dim buttonBrush As System.Drawing.Brush = Nothing
            If index = Me.SelectedIndex Then
                buttonBrush = New System.Drawing.Drawing2D.LinearGradientBrush(rect, _
                                                                                Me.iTabActiveBackColorGradient1, _
                                                                                Me.iTabActiveBackColorGradient2, _
                                                                                Drawing2D.LinearGradientMode.Vertical)
            Else
                buttonBrush = New System.Drawing.Drawing2D.LinearGradientBrush(rect, _
                                                                                Me.iTabBackColorGradient1, _
                                                                                Me.iTabBackColorGradient2, _
                                                                                Drawing2D.LinearGradientMode.Vertical)
            End If

            graph.FillPath(buttonBrush, path)
            buttonBrush.Dispose()

        End If

    End Sub
    Private Sub PaintTabBorder(ByVal graph As System.Drawing.Graphics, ByVal index As Integer, ByVal path As System.Drawing.Drawing2D.GraphicsPath)
        Dim borderPen As New Pen(Me.iTabBorderColor)
        If index = Me.SelectedIndex Then
            borderPen = New Pen(Me.iTabActiveBorderColor)
        End If

        graph.DrawPath(borderPen, path)
        borderPen.Dispose()
    End Sub
    Private Sub PaintTabImage(ByVal graph As System.Drawing.Graphics, ByVal index As Integer)
        Dim tabImage As Image = Nothing
        If Me.TabPages(index).ImageIndex > -1 AndAlso Me.ImageList IsNot Nothing Then
            tabImage = Me.ImageList.Images(Me.TabPages(index).ImageIndex)
        ElseIf Me.TabPages(index).ImageKey.Trim().Length > 0 AndAlso Me.ImageList IsNot Nothing Then
            tabImage = Me.ImageList.Images(Me.TabPages(index).ImageKey)
        End If
        If tabImage IsNot Nothing Then
            Dim rect As Rectangle = Me.GetTabRect(index)
            graph.DrawImage(tabImage, rect.X + 3, rect.Y + 2, 16, 16)
            'graph.DrawImage(tabImage, rect.Right - rect.Height - 4, 4, rect.Height - 2, rect.Height - 2)
        End If
    End Sub
    Private Sub PaintTabText(ByVal graph As System.Drawing.Graphics, ByVal index As Integer)
        'Check if tab image is available
        Dim tabImage As Image = Nothing
        If Me.TabPages(index).ImageIndex > -1 AndAlso Me.ImageList IsNot Nothing Then
            tabImage = Me.ImageList.Images(Me.TabPages(index).ImageIndex)
        ElseIf Me.TabPages(index).ImageKey.Trim().Length > 0 AndAlso Me.ImageList IsNot Nothing Then
            tabImage = Me.ImageList.Images(Me.TabPages(index).ImageKey)
        End If

        Dim rect As Rectangle = Me.GetTabRect(index)
        Dim rect2 As Rectangle

        If tabImage IsNot Nothing Then
            rect2 = New Rectangle(rect.Left + 19, rect.Top + 2, rect.Width - rect.Height - 7, rect.Height - 2)
            If index = 0 Then rect2 = New Rectangle(rect.Left + 19, rect.Top + 2, rect.Width - rect.Height - 8, rect.Height - 3)
        Else
            rect2 = New Rectangle(rect.Left + 5, rect.Top + 2, rect.Width - 7, rect.Height - 2)
            If index = 0 Then rect2 = New Rectangle(rect.Left + 5, rect.Top + 2, rect.Width - 12, rect.Height - 3)
        End If

        Dim tabtext As String = Me.TabPages(index).Text

        Dim format As New System.Drawing.StringFormat()
        If tabImage IsNot Nothing Then
            format.Alignment = StringAlignment.Near
        Else
            format.Alignment = StringAlignment.Center
        End If
        format.LineAlignment = StringAlignment.Center
        format.Trimming = StringTrimming.EllipsisCharacter
        format.FormatFlags = StringFormatFlags.FitBlackBox

        Dim forebrush As Brush = Nothing

        If Me.TabPages(index).Enabled = False Then
            forebrush = New SolidBrush(Me.iTabDisabledForeColor)
        Else
            forebrush = New SolidBrush(Me.iTabEnabledForeColor)
        End If

        Dim tabFont As Font = Me.Font
        If index = Me.SelectedIndex Then
            tabFont = New Font(Me.Font, FontStyle.Bold)
        End If
        graph.DrawString(tabtext, tabFont, forebrush, rect2, format)

        'this one has been targeted to be shown only on mouse over
        'Dim lRect As Rectangle = New Rectangle(rect2.X, (rect2.Y + rect2.Height), rect2.Width - 10, 2)
        'graph.FillRectangle(New SolidBrush(Color.Blue), lRect)

    End Sub
#End Region

#Region "   Overrides / Overloads"
    Protected Overrides Sub OnSelecting(ByVal e As System.Windows.Forms.TabControlCancelEventArgs)
        If e.Action = TabControlAction.Selecting _
            AndAlso e.TabPage IsNot Nothing _
            AndAlso e.TabPage.Enabled = False Then

            e.Cancel = True
            If e.TabPageIndex = 0 AndAlso Me.TabPages.Count = 1 Then
                If Me.TabPages(0).Controls.Count > 0 Then
                    Dim item As Form = TryCast(Me.TabPages(0).Controls(0), Form)
                    If item IsNot Nothing Then item.Close()
                End If
                Me.TabPages.RemoveAt(0)
            ElseIf e.TabPageIndex = 0 AndAlso Me.TabPages.Count > 1 Then
                e.Cancel = False
            End If
        End If
        MyBase.OnSelecting(e)
    End Sub
    Protected Overrides Sub OnSelected(ByVal e As System.Windows.Forms.TabControlEventArgs)
        If e.Action = TabControlAction.Selected _
            AndAlso e.TabPage IsNot Nothing _
            AndAlso e.TabPage.Enabled = False Then

            If Me.TabPages.Count > e.TabPageIndex + 1 Then
                Me.SelectedIndex = e.TabPageIndex + 1
            ElseIf e.TabPageIndex > 0 Then
                Me.SelectedIndex = e.TabPageIndex - 1
            End If
        End If
        MyBase.OnSelected(e)
        Me.Invalidate()
    End Sub
    Protected Overloads Overrides Sub OnCreateControl()
        MyBase.OnCreateControl()
        Me.OnFontChanged(EventArgs.Empty)
    End Sub
    Protected Overloads Overrides Sub OnFontChanged(e As EventArgs)
        MyBase.OnFontChanged(e)
        Dim hFont As IntPtr = Me.Font.ToHfont()
        SendMessage(Me.Handle, WM_SETFONT, hFont, CType((-1), IntPtr))
        SendMessage(Me.Handle, WM_FONTCHANGE, IntPtr.Zero, IntPtr.Zero)
        Me.UpdateStyles()
        Me.ItemSize = New Size(0, Me.Font.Height + Me.iTabHeightIncrementor)
    End Sub
    Protected Overrides Sub OnResize(e As System.EventArgs)
        MyBase.OnResize(e)
    End Sub
#End Region

#Region "   Shared Methods"
    <DllImport("user32.dll")> _
    Private Shared Function SendMessage(hWnd As IntPtr, Msg As Integer, wParam As IntPtr, lParam As IntPtr) As IntPtr
    End Function

#End Region

    Public Enum TabControlDisplayManager As Integer
        [Default]
        Framework
    End Enum

End Class

Public Class ThemedColors

#Region "    Variables and Constants "

    Private Const NormalColor As String = "NormalColor"
    Private Const HomeStead As String = "HomeStead"
    Private Const Metallic As String = "Metallic"
    Private Const NoTheme As String = "NoTheme"

    Private Shared _toolBorder As Color()
#End Region

#Region "    Properties "

    Public Shared ReadOnly Property CurrentThemeIndex() As Integer
        Get
            Return ThemedColors.GetCurrentThemeIndex
        End Get
    End Property

    Public Shared ReadOnly Property CurrentThemeName() As String
        Get
            Return ThemedColors.GetCurrentThemeName
        End Get
    End Property

    Public Shared ReadOnly Property ToolBorder() As Color
        Get
            Return ThemedColors._toolBorder(ThemedColors.CurrentThemeIndex)
        End Get
    End Property

#End Region

#Region "    Constructors "

    Private Sub New()
    End Sub

    Shared Sub New()
        Dim colorArray1 As Color()
        colorArray1 = New Color() {Color.FromArgb(127, 157, 185), Color.FromArgb(164, 185, 127), Color.FromArgb(165, 172, 178), Color.FromArgb(132, 130, 132)}
        ThemedColors._toolBorder = colorArray1
    End Sub

#End Region

#Region "Shared Functions"

    Private Shared Function GetCurrentThemeIndex() As Integer
        Dim theme As Integer = ColorScheme.NoTheme

        If VisualStyleInformation.IsSupportedByOS _
            AndAlso VisualStyleInformation.IsEnabledByUser _
            AndAlso Application.RenderWithVisualStyles Then


            Select Case VisualStyleInformation.ColorScheme
                Case NormalColor
                    theme = ColorScheme.NormalColor
                Case HomeStead
                    theme = ColorScheme.HomeStead
                Case Metallic
                    theme = ColorScheme.Metallic
                Case Else
                    theme = ColorScheme.NoTheme
            End Select
        End If

        Return theme
    End Function

    Private Shared Function GetCurrentThemeName() As String
        Dim theme As String = NoTheme

        If VisualStyleInformation.IsSupportedByOS _
            AndAlso VisualStyleInformation.IsEnabledByUser _
            AndAlso Application.RenderWithVisualStyles Then
            theme = VisualStyleInformation.ColorScheme
        End If

        Return theme
    End Function

#End Region

#Region "Enumerations"

    Public Enum ColorScheme
        NormalColor = 0
        HomeStead = 1
        Metallic = 2
        NoTheme = 3
    End Enum

#End Region

End Class